@extends('layouts.admin')

@section('content')
    <div class="panel panel-primary">
        <div class="panel-heading">
            用户管理
            <span class="navbar-right"><a class="btn btn-default btn-xs" href="{{url('admin/user/create')}}" style="margin-right: 15px" role="button">新增</a></span>
        </div>
        <div class="panel-body">
            <table class="table table-bordered">
                <tr>
                    <th>序号</th>
                    <th>用户名</th>
                    <th>帐号</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                @foreach($data as $value)
                    <tr>
                        <td>{{ $value->id }}</td>
                        <td>{{ $value->name }}</td>
                        <td>{{ $value->email }}</td>
                        <td>{{ $value->created_at }}</td>
                        <td><a href="{{ url('admin/user/'.$value->id.'/edit') }}">修改</a>
                            <a href="javascript:void(0);" onclick="destroy({{ $value->id }})">删除</a>
                        </td>
                    </tr>
                @endforeach
            </table>
        </div>
        <div class="panel-footer">
            {{ $data->links() }}
        </div>
    </div>
    <script type="text/javascript">
        /**
         * 异步删除分类
         * @param id
         */
        function destroy(id) {
            layer.confirm('您确认要删除这个用户嘛?', {
                btn: ['确定', '取消']  //按钮
            }, function () {
                $.post("{{ url('admin/user/') }}/" + id, {
                    '_method': 'delete',
                    '_token': "{{ csrf_token() }}"
                }, function (data) {
                    if (data.status == 0) {
                        layer.msg(data.message, {icon: 6});
                        setTimeout('location.href = location.href', 2000);
                    } else {
                        layer.msg(data.message, {icon: 5});
                    }
                });
            }, function () {

            });
        }
    </script>
@endsection
